/* ***** BEGIN LICENSE BLOCK *****
 * Copyright (C) 2010-2011, The VNREAL Project Team.
 * 
 * This work has been funded by the European FP7
 * Network of Excellence "Euro-NF" (grant agreement no. 216366)
 * through the Specific Joint Developments and Experiments Project
 * "Virtual Network Resource Embedding Algorithms" (VNREAL). 
 *
 * The VNREAL Project Team consists of members from:
 * - University of Wuerzburg, Germany
 * - Universitat Politecnica de Catalunya, Spain
 * - University of Passau, Germany
 * See the file AUTHORS for details and contact information.
 * 
 * This file is part of ALEVIN (ALgorithms for Embedding VIrtual Networks).
 *
 * ALEVIN is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License Version 3 or later
 * (the "GPL"), or the GNU Lesser General Public License Version 3 or later
 * (the "LGPL") as published by the Free Software Foundation.
 *
 * ALEVIN is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * or the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License and
 * GNU Lesser General Public License along with ALEVIN; see the file
 * COPYING. If not, see <http://www.gnu.org/licenses/>.
 *
 * ***** END LICENSE BLOCK ***** */
package vnreal.evaluations.metrics;

import org.apache.log4j.Logger;

import vnreal.ZNEW.GraphTest.Node;
import vnreal.ZNEW.GraphTest.WorkOnPaths;
import vnreal.algorithms.utils.SubgraphBasicVN.Utils;
import vnreal.network.substrate.SubstrateNetwork;
import vnreal.network.substrate.SubstrateNode;
import vnreal.resources.NEWEnergyResource;

public class EnergyConsumption extends /* SimpleEvaluation */AbstractEvaluation {

	public static Logger LOGGER = Logger.getLogger(EnergyConsumption.class);

	// private static boolean warning = false;

	public double calculate() {

		boolean isEnergyResource = true;
		String METHODNAME = "calculate()->";
		double result = 0;
		SubstrateNetwork sNetwork = stack.getSubstrate();
		for (SubstrateNode sn : sNetwork.getVertices()) {
			/**
			 * sprawdzamy czy dla danego wezla sn istnieje NewEnergyResource
			 * 
			 */
			if (Utils.getNewEnergyResource(sn) == null) {
				isEnergyResource = false;
				break;
			}
		}

		if (isEnergyResource) {
			LOGGER.debug(METHODNAME + "After if == null");

			LOGGER.debug(METHODNAME + "After if equals NEWEnergyResource");

			LOGGER.debug(METHODNAME + "size" + WorkOnPaths.virtualEdges.size());

			/*Set<String> enabledNodes = new HashSet<String>();
			for (Link lnk : WorkOnPaths.virtualEdges) {
				for (Path path : lnk.paths) {
					for (String node : path.allPaths) {
						enabledNodes.add(node);
					}
				}
			}

			LOGGER.debug(METHODNAME + "==========================");
			LOGGER.debug(METHODNAME + "set" + enabledNodes);
			LOGGER.debug(METHODNAME + "size" + enabledNodes.size());*/
			//TODO
			//LOGGER.debug(METHODNAME + "costofnodeon" + Algorithms.costOfNodeOn);

			/*for(Node node : WorkOnPaths.substrateNodes) {
				LOGGER.debug(METHODNAME + "node" + node);
				if(node.isOn) {
					LOGGER.debug(METHODNAME + "node.isOn");
					LOGGER.debug(METHODNAME + "result" + result);
					double x = (node.lineCards+node.ports+Double.parseDouble(node.energy))/0.625;
					node.energyConsumption=x-Double.parseDouble(node.energy);
					result += node.energyConsumption;
				}
			}*/
			//result = enabledNodes.size() * Algorithms.costOfNodeOn;
			for(Node node : WorkOnPaths.substrateNodes) {
				if(node.isOn) {
					result += node.energyConsumption;
				}
			}

		}

		else {
			System.err.println("No energy resource found!");
		}

		return result;
	}

	public final String toString() {
		return "EnergyConsumption";
	}
	
//	public void checkEnergyConsumption(NEWEnergyResource energy, Node n){
//		
//		n.energyConsumption= energy.getEnergy()-Double.parseDouble(n.energy);
//		
//		
//		
//	}
	
	
	
	
}